package gold.digger;

import gold.utils.InputUtil;

import java.util.*;
import java.util.stream.Collectors;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LCJZOF035 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public int findMinDifference(List<String> timePoints) {
            TreeSet<Integer> timeSet = new TreeSet<>();
            for (String timePoint : timePoints) {
                int timeSlot = Integer.parseInt(timePoint.split(":")[0]) * 60 + Integer.parseInt(timePoint.split(":")[1]);
                if (timeSet.contains(timeSlot)) return 0;
                timeSet.add(timeSlot);
            }

            int ans = Integer.MAX_VALUE;
            final List<Integer> timeList = timeSet.stream().collect(Collectors.toList());
            for (int i = 0; i < timeList.size() - 1; i++) {
                ans = Math.min(ans, timeList.get(i + 1) - timeList.get(i));
            }

            ans = Math.min(ans, timeList.get(0) + 24 * 60 - timeList.get(timeList.size() - 1));
            return ans;
        }
    }

    public void run() {
        System.out.println(new Solution().findMinDifference(Arrays.asList("23:59", "00:00")));
        System.out.println(new Solution().findMinDifference(Arrays.asList("00:00", "23:59", "00:00")));
    }

    public static void main(String[] args) throws Exception {
        LCJZOF035 an = new LCJZOF035();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
